<?php
require("../../../class2.php");
require("../library/admin/adminapi.php");
if (file_exists(THEME."admin_advanced_settings.php")) include(THEME."admin_advanced_settings.php");
else include("../templates/admin_advanced_settings.php");

if(!getperms("P")){header("location:".e_BASE."index.php"); exit; }
require_once(e_ADMIN."auth.php");

$status = $tp->toDB($_REQUEST['status']);
if ($status != "") $ns->tablerender(lan_global_status, lan_global_updated." - ".$status." ".lan_admin_advanced_records);

// Process the Form
if($_POST["subbed"]) {
    foreach ($_POST as $key => $value) {
        $updates[$key] = $tp->toDB($value);
    }
    unset($updates['subbed']);
    if (!isset($updates['catstyle_thumb_only']) && $shop_settings['catstyle_thumb_only'] == 'on') $updates['catstyle_thumb_only'] = "off";
    if (!isset($updates['catstyle_thumb_noscale'])&& $shop_settings['catstyle_thumb_noscale'] == 'on') $updates['catstyle_thumb_noscale'] = "off";
    if (!isset($updates['catstyle_name_bold']) && $shop_settings['catstyle_name_bold'] == 'on') $updates['catstyle_name_bold'] = "off";
    if (!isset($updates['product_list_admin']) && $shop_settings['product_list_admin'] == 'on') $updates['product_list_admin'] = "off";
    $counter = 0;
    foreach ($updates as $key => $value) {
        if ($updates[$key] != $shop_settings[$key]) {
            $status = $sql->db_Update($e107shop_db_name['advanced'], "tblvalue = '$value' where tblkey = '$key'", false);
            if ($status !== FALSE) {
                $shop_settings[$key] = $value;
                $counter++;
            }
            else $error .= lan_global_error."- record {$key}<br />";
        }
    }
    if ($error) $ns->tablerender(lan_global_status, $error);
    header("Location: ".e_SELF."?status=$counter");
}

// Display the form
$text = $tp->parseTemplate($ADMIN_ADVANCED_SETTINGS, FALSE);
$ns->tablerender(lan_admin_advanced_config_title, $text);

require_once(e_ADMIN."footer.php");
